package org.noip.amdg;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.font.TextAttribute;
import java.text.AttributedString;

public class LevelAnimation implements Animation {

	private final static int STEP_TIME = 20;
	
	private int fontSize = 28;

	private long lastTime;
	
	private AttributedString renderText = null;

	public LevelAnimation(int level) {
		renderText = new AttributedString("Level "+level);
	}

	/* (non-Javadoc)
	 * @see org.noip.amdg.Animation#renderFrame(java.awt.Graphics)
	 */
	public void renderFrame(Graphics graphics) {
		long currentTime = System.currentTimeMillis();
		if (currentTime - lastTime >= STEP_TIME) {
			
			// Time to render a frame
			if (fontSize > 0) {
				Font font = new Font("Sans", Font.BOLD, fontSize--);
				renderText.addAttribute(TextAttribute.FONT, font);
			}
			lastTime = currentTime;
		}
		
		graphics.drawString(renderText.getIterator(), 400, 300);
	}

	/* (non-Javadoc)
	 * @see org.noip.amdg.Animation#isDone()
	 */
	public boolean isDone() {
		return fontSize <= 0;
	}

	/* (non-Javadoc)
	 * @see org.noip.amdg.Animation#getStepTime()
	 */
	public int getStepTime() {
		return STEP_TIME;
	}
}
